package com.twitter.finagle.example.thrift

import com.twitter.finagle.example.thriftscala.Hello
import com.twitter.finagle.Thrift
import com.twitter.util.{Await, Future}
import scala.runtime.BoxedUnit
import com.twitter.logging.Logger

object ThriftClient {
  private val log = Logger.get(getClass)
  def main(args: Array[String]): Unit = {
    //#thriftclientapi
    val client = Thrift.client.build[Hello.MethodPerEndpoint]("localhost:3000")

    val api = client.hi()

    val response = api.onSuccess {
      response =>
        log.info(s"result: ${response}")
        println("Received response: " + response)


    }
   // Await.result(response)
    Await.ready(api)
   // Thread.sleep(3000)



    //#thriftclientapi

//    val f = client.hi()
//
//    f.onSuccess { message =>
//      log.info(s"result3: ${message}")
//      println(s"result: ${message}")
//    }.onFailure { err: Throwable =>
//      log.error(err.toString)
//    }
//    Await.ready(f)

  }
}